package springboard.auth.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import springboard.auth.bean.User;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("select permission_key from user__permission where user_id=#{userId}")
    List<String> selectUserPermissionKeys(@Param("userId") long userId);

    @Insert("insert ignore into user__permission(user_id, permission_key) values(#{userId}, #{permissionKey})")
    int insertUserPermission(@Param("userId") long userId, @Param("permissionKey") String permissionKey);

    @Insert("delete from user__permission where user_id=#{userId} and permission_key=#{permissionKey}")
    int deleteUserPermission(@Param("userId") long userId, @Param("permissionKey") String permissionKey);

    @Insert("delete from user__permission where user_id=#{userId}")
    int deleteAllUserPermission(@Param("userId") long userId);

    @Select("select role_key from user__role where user_id=#{userId}")
    List<String> selectUserRoleKeys(@Param("userId") long userId);

    @Insert("insert ignore into user__role(user_id, role_key) values(#{userId}, #{roleKey})")
    int insertUserRole(@Param("userId") long userId, @Param("roleKey") String roleKey);

    @Insert("delete from user__role where user_id=#{userId} and role_key=#{roleKey}")
    int deleteUserRole(@Param("userId") long userId, @Param("roleKey") String roleKey);

    @Insert("delete from user__role where user_id=#{userId}")
    int deleteAllUserRole(@Param("userId") long userId);

}
